package com.pinc.exam;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Test_Correct extends FlipActivity {
	private Question_Packet mQP;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.test_flip);

		mQP = (Question_Packet) getIntent().getSerializableExtra("packet");
		cur_qstn = getIntent().getIntExtra("number", 0);

		initWidget();
		showQuestion();
	}

	@Override
	protected void initWidget() {
		super.initWidget();

		/* set upbar */
		tv_title.setTextSize(16);

		b_prev.setVisibility(View.VISIBLE);
		b_prev.setText(getResources().getString(R.string.str_back));
		b_prev.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});

		LinearLayout ll_bar = (LinearLayout) findViewById(R.id.linearLayout_slctBar);
		ll_bar.setVisibility(View.GONE);
	}

	@Override
	protected String getQuestion(int qstn_no) {
		return mQP.mQuestion[qstn_no];
	}

	@Override
	protected String[] getSelections(int qstn_no) {
		return mQP.mArr_sel[qstn_no];
	}

	@Override
	protected void markSelection(TextView[] tv_sel, int qstn_no) {
		for( int i=0; i< GParam.SELECT_MAX; i++)
		{
			if ( i == mQP.mArr_ansPaper[qstn_no]-1)
			{
				if ( mQP.mArr_answer[qstn_no][i])
					tv_sel[i].setTextColor(getResources().getColor(R.color.correct));
				else
					tv_sel[i].setTextColor(getResources().getColor(R.color.selected));
			}
			else if ( mQP.mArr_answer[qstn_no][i])
			{
				tv_sel[i].setTextColor(getResources().getColor(R.color.answer));
			}
			else
			{
				tv_sel[i].setTextColor(Color.BLACK);
			}
		}
	}

	@Override
	protected int getQuestionCnt() {
		return mQP.mQstn_total;
	}

	@Override
	protected void postHandle(int no) {
		tv_title.setText(String.format("%s\n(%d/%d)", getResources().getString(R.string.str_quiz_result), no+1, mQP.mQstn_total));
	}

	@Override
	protected int getImageIndex(int qstn_no) {
		return mQP.mImgID[qstn_no];
	}

}
